package com.neusoft.utils.net;

import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;

public class NetUtil {
	private static void bindPort(String host, int port) throws Exception { 
	    Socket s = new Socket(); 
	    s.bind(new InetSocketAddress(host, port)); 
	    s.close(); 
	} 
	public static boolean isPortAvailable(int port) {
	    try { 
	        bindPort("0.0.0.0", port); 
	        bindPort(InetAddress.getLocalHost().getHostAddress(), port); 
	        return true; 
	    } catch (Exception e) { 
	        return false; 
	    } 
	}
}
